// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_CEGUI_TEXTURE__
#define __H_MK_CEGUI_TEXTURE__

#include "mk_texture.h"
#include "CEGUI.h"

namespace MK3DE
{
	class MK3DE_API CCEGUITexture : public CEGUI::Texture
	{
	public:
		CCEGUITexture(CEGUI::Renderer* owner);
		virtual ~CCEGUITexture();

		/*!
		\brief
		Returns the current pixel width of the texture

		\return
		ushort value that is the current width of the texture in pixels
		*/
		virtual	CEGUI::ushort	getWidth(void) const;

		/*!
		\brief
		Returns the original pixel width of the data loaded into the texture.

		\return
		ushort value that is the original width, in pixels, of the data last
		loaded into the texture.

		\note 
		for compatibility reason this method is optional the auto scale 
		issue mantis ticket # 0000045 is not fixed for renderer that do 
		not handle this. 
		*/
		virtual CEGUI::ushort getOriginalWidth(void) const;

		/*! 
		\brief 
		Returns the current scale used for the width of the texture 

		\return 
		float value that denotes the horizontal scaling required to
		accurately map pixel positions to texture co-ords.
		*/
		virtual float getXScale(void) const;

		/*!
		\brief
		Returns the current pixel height of the texture

		\return
		ushort value that is the current height of the texture in pixels
		*/
		virtual	CEGUI::ushort getHeight(void) const;

		/*!
		\brief
		Returns the original pixel height of the data loaded into the texture.

		\return
		ushort value that is the original height, in pixels, of the data last
		loaded into the texture.

		\note
		for compatibility reason this method is optional the auto scale 
		issue mantis ticket # 0000045 is not fixed for renderer that do 
		not handle this. 
		*/
		virtual CEGUI::ushort getOriginalHeight(void) const;

		/*! 
		\brief 
		Returns the current scale used for the height of the texture 

		\return 
		float value that denotes the vertical scaling required to
		accurately map pixel positions to texture co-ords.
		*/
		virtual float getYScale(void) const;

		/*!
		\brief
		Loads the specified image file into the texture.  The texture is resized as required to hold the image.

		\param filename
		The filename of the image file that is to be loaded into the texture

		\param resourceGroup
		Resource group identifier to be passed to the resource provider when loading the image file.

		\return
		Nothing.
		*/
		virtual void loadFromFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup);


		/*!
		\brief
		Loads (copies) an image in memory into the texture.  The texture is resized as required to hold the image.

		\param buffPtr
		Pointer to the buffer containing the image data

		\param buffWidth
		Width of the buffer (in pixels as specified by \a pixelFormat)

		\param buffHeight
		Height of the buffer (in pixels as specified by \a pixelFormat)

		\param pixelFormat
		PixelFormat value describing the format contained in \a buffPtr

		\return
		Nothing.
		*/
		virtual void loadFromMemory(const void* buffPtr, CEGUI::uint buffWidth, CEGUI::uint buffHeight, CEGUI::Texture::PixelFormat pixelFormat);

	public:
		BOOL _CreateTexture(DWORD size);
		BOOL _CreateTexture(const char* fileName);

		CTexture2D* _GetTexture() { return _texture; }

	private:
		void __FreeTexture();
		void __UpdateCachedScaleValues();

	private:
		CTexture2D* _texture;

		CEGUI::String _fileName;
		CEGUI::String _resourceGroup;
		BOOL _isMemoryTexture;

		float _xScale;
		float _yScale;
	};
};

#endif // __H_MK_CEGUI_TEXTURE__